import xmlrpclib
from xmlrpcserver import XmlRpcServer
from google.appengine.ext import db
import datetime

class XmlRpcWrapper():
    """
    This class acts as a wrapper around a python object. It copies
    the underlying objects methods so they can be made avaliable to the XmlRpcServer class
    If the methods are public, the first argument "meta" is stripped off of the call from the 
    XMLRpcServer object, so that we can use a generic underlying object for the api call. 
    Private methods (i.e. those starting with an "_" are copied as is, as they are not exposed as
    remote procedures
    """
    def __init__(self, obj):
        self._obj=obj
        for a in dir(obj):
            m=getattr(obj, a)
            if callable(m) and a[0]!="_":
                    self.__dict__[a] = self._call_api_method(a)
                    self.__dict__[a].__doc__ = m.__doc__
                                
    def _call_api_method(self, method):
        return lambda meta, *args, **kwds: getattr(self._obj, method)(*args, **kwds)
    
